<div id="admin-content">
	<h3>Thêm sản phẩm mới</h3>
	<div id="body">
		<?php
		if($this->error):
			?>
		<div id="error">
			<p>Đã có lỗi xảy ra.</p>
		</div>
		<?php
		endif;
		?>
		<?php
		$form = $this->form;
		$form->prepare();
		$form->setAttribute('action',$this->url(NULL,array('controller'=>'manage','action'=>'upload')));
		$form->setAttribute('method','post');
		$form->setAttribute('class','form-horizontal');
		$form->setAttribute('role','form');
		echo $this->form()->openTag($form);
		?>
		<div class="form-group">
			<?php echo $this->formLabel($form->get('maHang')); ?>
			<?php
			echo '<div class="col-sm-4">';
			echo $this->formElement($form->get('maHang'));
			echo $this->formElementErrors($form->get('maHang'));
			echo '</div>';
			?>
		</div>
		<div class="form-group">
			<?php echo $this->formLabel($form->get('ten')); ?>
			<?php
			echo '<div class="col-sm-4">';
			echo $this->formElement($form->get('ten'));
			echo $this->formElementErrors($form->get('ten'));
			echo '</div>';
			?>
		</div>
		<div class="form-group">
			<?php echo $this->formLabel($form->get('hinhAnh1')); ?>
			<?php
			echo '<div class="col-sm-4">';
			echo $this->formElement($form->get('hinhAnh1'));
			echo $this->formElementErrors($form->get('hinhAnh1'));
			echo '<br/><img width="100%" height="auto" id="preview1">';
			echo '</div>';
			?>
			<img class="">
		</div>
		<div class="form-group">
			<?php echo $this->formLabel($form->get('hinhAnh2')); ?>
			<?php
			echo '<div class="col-sm-4">';
			echo $this->formElement($form->get('hinhAnh2'));
			echo $this->formElementErrors($form->get('hinhAnh2'));
			echo '<br/><img width="100%" height="auto" id="preview2">';
			echo '</div>';
			?>
			<img class="">
		</div>
		<div class="form-group">
			<?php echo $this->formLabel($form->get('hinhAnh3')); ?>
			<?php
			echo '<div class="col-sm-4">';
			echo $this->formElement($form->get('hinhAnh3'));
			echo $this->formElementErrors($form->get('hinhAnh3'));
			echo '<br/><img width="100%" height="auto" id="preview3">';
			echo '</div>';
			?>
			<img class="">
		</div>
		<div class="form-group">
			<?php echo $this->formLabel($form->get('soLuong')); ?>
			<?php
			echo '<div class="col-sm-4">';
			echo $this->formElement($form->get('soLuong'));
			echo $this->formElementErrors($form->get('soLuong'));
			echo '</div>';
			?>
		</div>
		<div class="form-group">
			<?php echo $this->formLabel($form->get('tinhTrang')); ?>
			<?php
			echo '<div class="col-sm-4">';
			echo $this->formElement($form->get('tinhTrang'));
			echo $this->formElementErrors($form->get('tinhTrang'));
			echo '</div>';
			?>
		</div>
		
		<div class="form-group">
			<?php echo $this->formLabel($form->get('ngayNhap')); ?>
			<?php
			echo '<div class="col-sm-4">';
			echo $this->formElement($form->get('ngayNhap'));
			echo $this->formElementErrors($form->get('ngayNhap'));
			echo '</div>';
			?>
		</div>
		<div class="form-group">
			<?php echo $this->formLabel($form->get('gia')); ?>
			<?php
			echo '<div class="col-sm-4">';
			echo $this->formElement($form->get('gia'));
			echo $this->formElementErrors($form->get('gia'));
			echo '</div>';
			?>
		</div>
		<div class="form-group">
			<?php echo $this->formLabel($form->get('loaiHang')); ?>
			<?php
			echo '<div class="col-sm-4">';
			echo $this->formElement($form->get('loaiHang'));
			echo $this->formElementErrors($form->get('loaiHang'));
			echo '</div>';
			?>
		</div>
		<div class="form-group">
			<?php echo $this->formLabel($form->get('moTa')); ?>
			<?php
			echo '<div class="col-sm-6">';
			echo $this->formElement($form->get('moTa'));
			echo $this->formElementErrors($form->get('moTa'));
			echo '</div>';
			?>
		</div>
		<div class="form-group">
			<label for="submit" class='col-sm-3 control-label'> </label>
			<div class="col-sm-4">
				<?php echo $this->formElement($form->get('submit'));?>
			</div>
		</div>
		<?php $this->form()->closeTag($form); ?>
		<button class="btn btn-primary btn-lg hidden" type="button" data-toggle="modal" data-target="#myModal" id="showModalButton">
		</button>
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
						<h4 class="modal-title" id="myModalLabel">Nhập thông tin số lượng chi tiết</h4>
					</div>
					<div class="modal-body" id="slct">
					<form class="form-horizontal" role="form" name="otherForm">
						<?php for($i = 34; $i < 41; $i++){
							echo '
							<div class="form-group">
								<label class="col-sm-3 control-label" for="size'.$i.'">
								 Size '.$i.'
								</label>
								<div class="col-sm-4">
									<input type="text" id="size'.$i.'" class="form-control" placeholder="Số lượng có sẵn" value="0"/>
								</div>
							</div>
							';
						}?>
					</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal" onclick="saveChanges();">Close</button>
					</div>
				</div>
			</div>
		</div>

	</div>
</div>

<script>
	function clickModal(){
		$('#showModalButton').click();
	}

	var inputs;
	var vals;	
	var slct = '';
	function saveChanges(){
		console.log("save changes");
		var inputs = $('#slct input');	
		var sum = 0;
		var slct = '';
		for(i = 0; i < inputs.length; i++){
			sum += parseInt($(inputs[i]).val());
			if(i != inputs.length - 1)
				slct = slct + $(inputs[i]).val() +"|";
			else
				slct = slct + $(inputs[i]).val();
 		}
 		$('#soLuong').val(sum);
 		$('#tinhTrang').val(slct);
	}
</script>